package com.fileshare.web.controller.admin.view;

import com.fileshare.web.controller.admin.BaseController;
import com.fileshare.web.dto.Vo.ArticleVo;
import com.fileshare.web.dto.info.WebInfo;
import com.fileshare.web.properties.WebProperties;
import com.fileshare.web.service.ArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin/resource")
@PreAuthorize("@auth.matchAny('administrator')")
public class ResourceAdminController extends BaseController {

    @Resource
    private WebProperties webProperties;
    @Resource
    private ArticleService articleService;

    @GetMapping("/article")
    public String index(HttpServletRequest request, @RequestParam(defaultValue = "1") Integer page) {

        WebInfo webInfo = new WebInfo();
        webInfo.setTitle("文章管理");
        request.setAttribute("webInfo", webInfo);
        PageInfo<ArticleVo> articlePageInfo = articleService.getArticles(page, webProperties.getLimit());
        request.setAttribute("articlePageInfo", articlePageInfo);
        return view("article/index");
    }
}
